function [Dh, Dv, Dd1,Dd2] = extract_details_wavelets(varargin)
%EXTRACT_DETAILS_WAVELETS Extracts horizontal, vertical and diagonal details on
%multiple scales using discrete wavelet transform. Details on each scale
%are interpolated to the full resolution of input image. Those input maps
%should serve as inputs for later stages of edge detection processing.
%
% Syntax:
%   [Dh, Dv, Dd] = extract_details_wavelets(I, params)
%   [Dh, Dv, Dd] = extract_details_wavelets(I)
% Inputs:
%   I - Input gray scale image.
%   params - Structure with parameter valued.
%       .num_levels - Number of wavelet transformation levels
%                     Possible values: 1 - maxPyrHt
%                     4 (default)
%                     
%       .wavelet_filter - Filter used for wavelet decomponsition
%                         Possible values: 'qmf5' (default), 'qmf8',
%                         'qmf9', 'qmf12', 'qmf13', 'qmf16', 'gauss3',
%                         'gauss5', 'haar', 'daub2', 'daub3', 'daub4'
%
% Outputs:
%   Dh - Array of horizontal detail planes (num_levels planes).
%   Dv - Array of vertical detail planes (num_levels planes).
%   Dd - Array of diagonal detail planes (num_levels planes).
%
% Example:
%

% Created on:    2014-01-04 (Dragomir El Mezeni)
% Last revision: 2014-01-23 (Mohamed Marouf)  

%------------- BEGIN CODE --------------

    params = struct('num_levels', 4, ...
                    'wavelet_filter', 'haar');
                        
    switch nargin
        case 1
            % Nothing to be done
        case 2
            params = merge_structs(params, varargin{2});
        otherwise
        error('Invalid number of input args.');
    end
    
    I = varargin{1};
    
    max_num_levels = maxPyrHt(size(I), size(namedFilter(params.wavelet_filter)));
    
    if (params.num_levels < 1) || (params.num_levels > max_num_levels)
       num_levels = max_num_levels;
    else
       num_levels = params.num_levels;
    end
    
    full_size = size(I); 
    
    [Wpyr, Addr] = buildWpyr(I, num_levels, params.wavelet_filter);

    for level = 1:1:num_levels    
        Lh = wpyrBand(Wpyr, Addr, level, 1);
        Lv = wpyrBand(Wpyr, Addr, level, 2);
        Ld = wpyrBand(Wpyr, Addr, level, 3);
    
        Dh{level} = imresize(Lh, full_size);
        Dv{level} = imresize(Lv, full_size);
        Dd1{level} = imresize(Ld, full_size);
        Dd2{level}=[];
    end
    
end
